﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeJC.DAL.Model;

namespace DeJC.BLL.Managers {
    public static class ProductManager
    {
        private static UnitOfWork unitOfWork = new UnitOfWork();
        public static IEnumerable<Product> GetProducts()
        {
            IEnumerable<Product> products;
            using(UnitOfWork unitOf = new UnitOfWork())
            {
                products=unitOf.ProductRepository.GetAll();    
            }

            return products;
        }

        public static bool AddProduct(Product product) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                unitOfWork.ProductRepository.Add(product);
                unitOfWork.Save();
            }
            return true;
        }

        // public bool UpdateProduct(Product product, int id)
        // {
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // var productEntity = unitOfWork.ProductRepository.GetById(id);
        // productEntity.Title = product.Title;
        // productEntity.FirstName = product.FirstName;
        // productEntity.LastName = product.LastName;
        // productEntity.ModifiedDate = DateTime.Now;
        // unitOfWork.Save();
        // }
        // return true;
        // }

        public static bool DeleteProduct(int id) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                Product product=unitOfWork.ProductRepository.GetById(id);
                product.Deleted=true;
                product.DeletedDate=DateTime.Now;
                unitOfWork.Save();
            }
            return true;
        }

        // public List<Product> GetProductPaged(int page, int rows, out int totalCount)
        // {
        // List<Product> products;
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // products = unitOfWork.ProductRepository.GetProductPaged
        // (page, rows, out totalCount);
        // }
        // return products;
        // }
        public static Product GetById(int id) {
            Product product;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                product=unitOfWork.ProductRepository.GetById(id);
            }
            return product;
        }
    }
}
